package com.anyonavinfo.cpaddemo.data.weatherinfo.source.local;

import android.content.Context;
import android.content.SharedPreferences;

import com.anyonavinfo.cpaddemo.Application;
import com.anyonavinfo.cpaddemo.data.weatherinfo.WeatherInfo;

/**
 * Created by ZuiC on 2017/2/8.
 */

public class WeatherInfoLocalDataSourceHelper {

    private Context mContext;

    public WeatherInfoLocalDataSourceHelper(){
        mContext = Application.getContextObject();
    }

    public void saveWeatherInfo(String temp, String type){
        SharedPreferences sharedPreferences = mContext.getSharedPreferences("WeatherInfo", 0);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("Temp", temp);
        editor.putString("Type", type);
        editor.commit();
    }

    public WeatherInfo getWeatherInfo(){
        SharedPreferences sharedPreferences = mContext.getSharedPreferences("WeatherInfo", 0);
        WeatherInfo weatherInfo = new WeatherInfo();
        weatherInfo.setCurTemperature(sharedPreferences.getString("Temp","NULL"));
        weatherInfo.setCurWeatherType(sharedPreferences.getString("Type","NULL"));
        return weatherInfo;
    }

}
